#include <iostream>
#include <math.h>
#include <ctime>

using namespace std;

// template <typename T>
class SelfSqrt
{
	public:
		float sqrtSlove(float  num);
		void para_init(int,float ,float,float);
	private:
		int max_iter_num;
		float x;
		float eps;
		float delta;
};

void SelfSqrt::para_init(int & max_iter_num,float& eps,float& delta)
{
	max_iter_num = (20 > max_iter_num > 0)? max_iter_num: 20 ;
	eps =  eps;
	delta  =( 1 > delta > 0)? delta:1;
}

float SelfSqrt::sqrtSlove(float num)
{
	int i(0);
	for ( float x=0 ; x*x <= num/2 ; ++x)
		eps =fabs( x*x - num);
	while ( eps >= delta && i<max_iter_num )
	{
	//	x   = ((eps+num*2)/x)/2;
		x   = (x+num/x)/2;
		eps = fabs(x*x - num );
		i++;
	}
	return x ;
}

int main()
{
	time_t now_time;
	now_time = time(NULL);
	SelfSqrt a;
	a.para_init(20,0,0,0.001);
	long int  tmp = now_time;	
	cout << "The result of "<< tmp <<"is "<< a.sqrtSlove(tmp)<<endl;
	
}


